local que_jingqing = fk.CreateSkill {
    name = "que_jingqing",
    tags = { Skill.Switch },
}

Fk:loadTranslationTable {
    ["que_jingqing"] = "净清",
    [":que_jingqing"] = "转换技，阳：出牌阶段，你可以摸X张牌并失去一点体力，然后视为使用一张因此获得牌中的一张；阴：当你受到或造成伤害后，摸X张牌，令伤害来源或目标随机弃置一张牌(X为你的体力值)。",

    ["#jingqing-ask"] = "净清：是否摸 %arg 张牌，令 %src 随机弃置一张牌",
    ["#jingqing-ask2"] = "净清：是否摸 %arg 张牌，令 %src 随机弃置一张牌",
}
que_jingqing:addEffect("active", {
    anim_type = "switch",
    prompt = function(self, player)
        return "净清：你可以摸" .. player.hp .. "张牌，失去一点体力，视为使用一张因此获得的牌"
    end,
    can_use = function(self, player)
        return player:getSwitchSkillState(que_jingqing.name, false) == fk.SwitchYang
    end,
    card_filter = Util.FalseFunc,
    target_filter = Util.FalseFunc,
    on_use = function(self, room, effect)
        local player = effect.from
        local cards = player:drawCards(player.hp, que_jingqing.name)
        room:loseHp(player, 1, que_jingqing.name)
        local ids = {}
        for _, id in ipairs(cards) do
            local card = Fk:getCardById(id)
            if card.type == Card.TypeBasic or card:isCommonTrick() then
                table.insertIfNeed(ids, card.name)
            end
        end
        if #ids > 0 then
            room:askToUseVirtualCard(player, {
                name = ids,
                skill_name = que_jingqing.name,
                cancelable = true,
                extra_data = {
                    extraUse = true,
                },
                prompt = "净清：请选择要使用的牌",
            })
        end
    end,
})

que_jingqing:addEffect(fk.Damaged, {
    anim_type = "switch",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(que_jingqing.name) and data.from and
            player:getSwitchSkillState(que_jingqing.name, false) == fk.SwitchYin
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player,
            { skill_name = que_jingqing.name, prompt = "#jingqing-ask:" .. data.from.id .. "::" .. player.hp })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:drawCards(player.hp, que_jingqing.name)
        if #data.from:getCardIds("he") > 0 then
            local card = table.random(data.from:getCardIds { Player.Hand, Player.Equip })
            room:throwCard({ card }, que_jingqing.name, data.from, player)
        end
    end,
})

que_jingqing:addEffect(fk.Damage, {
    anim_type = "switch",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(que_jingqing.name) and data.to and
            player:getSwitchSkillState(que_jingqing.name, false) == fk.SwitchYin
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player,
            { skill_name = que_jingqing.name, prompt = "#jingqing-ask2:" .. data.to.id .. "::" .. player.hp })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:drawCards(player.hp, que_jingqing.name)
        if #data.to:getCardIds("he") > 0 then
            local card = table.random(data.to:getCardIds { Player.Hand, Player.Equip })
            room:throwCard({ card }, que_jingqing.name, data.to, player)
        end
    end,
})
return que_jingqing
